import { _decorator, Component, EditBox, Node } from 'cc';
import ViewBase from '../../engine/ViewBase';
import { AccountModel } from '../model/AccountModel';
import { UIHelper } from '../util/UIHelper';
import { EventManager } from '../../engine/EventManager';
import UIManager from '../../engine/UIManager';
import { ViewConfig } from '../config/ViewConfig';
import { HttpHelper } from '../../net/HttpHelper';
import { Logger } from '../../engine/Logger';
const { ccclass, property } = _decorator;

@ccclass('ViewAccount')
export class ViewAccount extends ViewBase {

    private txtAccount: EditBox
    private txtPass: EditBox
    private btnRegister: Node
    private btnLogin: Node

    onEnable() {
        super.onEnable()
        AccountModel.instance.init()
        this.txtAccount = this.getChild(this.node, "txtAccount", EditBox);
        this.txtAccount.string = AccountModel.instance.account
        this.txtPass = this.getChild(this.node, "txtPass", EditBox);
        this.txtPass.string = AccountModel.instance.password
        this.btnRegister = this.findChild(this.node, "btnRegister")
        EventManager.onAddEvent(this.btnRegister, () => {
            UIManager.instance.showView(ViewConfig.viewConfig.ViewRegister)
        })
        this.btnLogin = this.findChild(this.node, "btnLogin")
        EventManager.onAddEvent(this.btnLogin, () => {
            if (this.txtAccount.string == "" || this.txtPass.string == "") {
                UIHelper.showTip("请输入账号密码")
                return
            }
            HttpHelper.account_auth(this.txtAccount.string, this.txtPass.string)
        })
    }

   



}

